import java.util.*

fun listReadOnly(){
    val list= listOf("Apple","Banana111","Orange66666","Pear","Grape")
    for (fruit in list){
        println(fruit)
    }
//    val lambda={list1:String -> list1.length}
//    val maxSetLength= list.maxByOrNull({fruit:String ->fruit.length})
//    val maxSetLength= list.maxByOrNull(){fruit:String ->fruit.length}
    val maxSetLength=list.maxByOrNull { it.length }
    println("List's length is "+maxSetLength)//取最长的单词
}
fun listReadWrite(){
    val list= mutableListOf("米饭","青菜","面条","年糕","煎饼","胡萝卜")
    for (food in list){
        println(food)
    }
    list.add(1,"花生米")
    for (food in list){
        println(food)
    }


}
fun setReadOnly(){
 val set= setOf("Apple","Banana","Orange","Pear","Grape")

     println(set)

}
/*
fun setRead_Write(){
 val mutableSetOf
}
*/
fun mapReadOnly(){
 val map= mapOf("米饭" to 1,"青菜" to 2,"面条" to 3,"年糕" to 4,"煎饼" to 5,"胡萝卜" to 6)
//  val lambda={map:String ->map.length}
//    println("MAX length is "+map.maxBy(lambda))
 // 循环遍历map
 for((food,number)in map)
     println("food is "+food + "number is "+number)
}

//将单词转换成大写
fun upperWord(){
    val list= listOf("Apple","Banana111","Orange66666","Pear","Grape")
    val newList=list.map { it.uppercase(Locale.getDefault()) }
    println("转化后：")
    for (fruit in newList)
        println(fruit)

}

//只保留长度大于等于6的单词
fun filterTest():Int{
    val list= listOf("Apple","Banana111","Orange66666","Pear","Grape")
    val newList2=list.filter { it.length >=5 }.map { it.uppercase() }
    println()
    for (fruit in newList2)
        println(fruit)
    return 666

}

/*public interface Runnable{
    void run();
}*/

//判断文本长度，使用?:和?.

fun getTextLength(text:String)=text?.length?:0
fun getTextLength2(str:String="hello")=str?.length?:0